package com.leehongrim.platformai.common.util;

import com.alibaba.fastjson2.JSON;
import com.hw.langchain.llms.ollama.Ollama;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;

@Slf4j
public class OllamaUtils {

    private static String ollama_base_url = "http://localhost:11434";

    private OllamaUtils(){}

    private static volatile Ollama ollama;

    public static Ollama getOllamaBuilder(){
        if(ollama == null){
            synchronized (Ollama.class) {
                if(ollama == null){
                    ollama = Ollama.builder()
                            .baseUrl(ollama_base_url)
                            .model("qwen2:7b")
                            .temperature(0f)
                            .build()
                            .init();
                }
            }
        }
        return ollama;
    }

    public static String send(String msg){
        if(StringUtils.isAllBlank(msg)){
            return "---无内容---";
        }
        return getOllamaBuilder().predict(msg);
    }



}
